<?php

defined('DS') or define('DS',DIRECTORY_SEPARATOR);
defined('ENGINEX_PATH') or define('ENGINEX_PATH',dirname(__FILE__));

class EngineX {

	private static $_application;
	private static $classMap = array();

	public static function createApplication($config){
		if (self::$_application !== null){
			throw new ErrorException("Only one copy of application can be loaded");
		} else {
			return (self::$_application = new Application($config));
		}
	}
	
	public static function app(){
		return self::$_application;
	}
	
	public static function autoload($className){
		if (!isset(self::$classMap[$className])){
			include ENGINEX_PATH.DS."C".$className.".php";
			array_push(self::$classMap,$className);
		} else {
			throw new ErrorException("Class is already loaded");
		}
	}
}

spl_autoload_register(array('EngineX','autoload'));

?>